<template>
<div class="box">
    <div class="login" >
<img src="@/assets/login/bg1.png" alt="">
<div style="width:353px;height:426px">
   <h3 style="display:flex;align-items: center;justify-content: center;margin-top:60px"><span><img src="@/assets/login/logo1.png" alt="" style="width:33px;height:36px;margin-right:10px"></span>汇客教育</h3>
<el-form :model="formDate" :rules="formDateRules" style="    width: 250px;
    margin: 50px auto;">
    <el-form-item style=" margin-bottom: 35px;" prop="username">
        <el-input v-model="formDate.username"  placeholder="请输入账号">
            <template #prefix>
<el-icon><User /></el-icon>
            </template>
        </el-input>
    </el-form-item>
    <el-form-item style=" margin-bottom: 35px;" prop="password">
        <el-input type="password" v-model="formDate.password"  placeholder="请输入密码">
                        <template #prefix>
<el-icon><Lock /></el-icon>
            </template>
        </el-input>
    </el-form-item>
    <el-form-item style=" margin-bottom: 35px;" prop="code">
        <el-input v-model="formDate.code"  placeholder="验证码">
                        <template #prefix>
<el-icon><CircleCheck /></el-icon>
            </template>
            <template #suffix>
                <img src="" alt="" style="width: 76px;
height: 29px;">
            </template>
        </el-input>
    </el-form-item>
    <el-form-item style=" margin-bottom: 35px;">
      <el-button type="primary" round style="width: 250px" @click="loginApi">登录</el-button>
    </el-form-item>
</el-form>
</div>
 
    </div>
</div>
</template>
<script setup>
import {reactive} from "vue"
import {login} from '@/api/login.js'
import {ElMessage} from 'element-plus'
import {useRouter} from 'vue-router'
import {useToken} from '@/stores/counter.js'
defineOptions({
    name:"LoginPage"
})
const router = useRouter()
const formDate = reactive({
    username:'demo',
    password:'123456',
    code:'5'
})
const formDateRules=reactive({
    username:[
    { required: true, message: '请输入正确的用户名', trigger: 'blur' },
    // { min: 3, max: 5, message: 'Length should be 3 to 5', trigger: 'blur' },
  ],
  password:[
     { required: true, message: '请输入正确的密码', trigger: 'blur' },
  ],
   code:[
     { required: true, message: '请输入正确的验证码', trigger: 'blur' },
  ]
})
const loginApi=async()=>{
const res = await login(formDate)
console.log(res.data.data.token);
 await ElMessage.success('登陆成功')
  const {setToken} = useToken()
 await setToken(res.data.data.token)
await router.push('/')
}

</script>

<style lang="less" scoped>
.box{
    width: 100vw;
    height: 100vh;
    background-color: #2B303B;
    .login{
        display: flex;
        width: 886px;
        height: 426px;
        background-color: #fff;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%,-50%);
        border-radius: 10px;
        img{
            width: 553px;
            height: 426px;
        }
       .el-input__wrapper{
           margin-bottom: 20px;
        }
    }
}
</style>